package com.zny.sescore.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

public class JsonUtil {
    public JsonUtil() {
    }

    public static String objectToString(Object obj) {
        if (obj == null) {
            return "";
        } else {
            try {
                return JSON.toJSONString(obj, false);
            } catch (Exception var2) {
                return null;
            }
        }
    }

    public static Object stringToObject(String json, Class cls) {
        try {
            return json == null ? null : JSON.parseObject(json, cls);
        } catch (Exception var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public static <T> T stringToRealObject(String jsonString, Class<T> clazz) {
        if (jsonString == null) {
            return null;
        } else {
            try {
                return JSON.parseObject(jsonString, new TypeReference<T>() {
                });
            } catch (Exception var3) {
                var3.printStackTrace();
                return null;
            }
        }
    }

    public static <T> T stringToTypeReference(String jsonString, TypeReference<T> type) {
        if (jsonString != null && type != null) {
            try {
                return JSON.parseObject(jsonString, type);
            } catch (Exception var3) {
                var3.printStackTrace();
                return null;
            }
        } else {
            return null;
        }
    }
}
